<?php

namespace app\api\controller;

use app\BaseController;

use app\common\model\ArticleModel;

class Article extends BaseController
{
    public function list(){
        $category_id = $this->request->param('category_id/d',0);
        $where=[
            ['is_delete','=',0]
        ];
        if($category_id > 0){
            $where[] = ['category_id','=',$category_id];
        }else{
            $where[] = ['firm_id','=',$this->request->staff_info->firm_id];
        }
        $list = ArticleModel::field('article_id,thumbnail,title,desc')->where($where)
            ->limit($this->request->limit)
            ->page($this->request->page)
            ->order('sort','desc')
            ->select();
        return success($list);
    }
    
    public  function detail(){
        $article_id = $this->request->param('article_id/d',0);
        if(empty($article_id)){
            return error('错误操作');
        }
        if(null === $articleModel = ArticleModel::find($article_id)){
            return error('内容不存在');
        }
        return success($articleModel);
    }
}
